function setfkdui(){
	 var mb=$("#bjfkd_A_ADATAL input[qucln=MAN_BUSINESS]").val();
		$.ajax({
			type:'post',
			url:_m_url+'bjTopic/getzhanghaobymanid',
			data:{'mb':mb},
			success:function(data){
	         if(data.length==1){
	        	$("#bjfkd_A_ADATAL input[qucln=BANK_ID]").val(data[0].ID);
				$("#bjfkd_A_ADATAL input[qucln=BANK_ID]").attr("chan","T");
				$("#bjfkd_A_ADATAL input[qucln=BANK_ID]").next().val(data[0].BANK_NO);
				
				$("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
				$("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
				$("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);
				
				$("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
				$("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
				$("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
	         }else{
	        	 $("#bjfkd_A_ADATAL input[qucln=BANK_ID]").val("");
				 $("#bjfkd_A_ADATAL input[qucln=BANK_ID]").attr("chan","T");
				 $("#bjfkd_A_ADATAL input[qucln=BANK_ID]").next().val("");
				 
				 $("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").val("");
				 $("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
				 $("#bjfkd_A_ADATAL input[qucln=BANK_NAME]").next().val("");
					
				 $("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").val("");
				 $("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
				 $("#bjfkd_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val("");
					
	         }
			}
		});
}
/**
 * 编务费用  付款对象拉取账号
 * 
 */
function getAccount(){
	 var mb=$("#ind_addWinTable input[qucln=MAN_BUSINESS]").val();//bxfy_addWinForm
		$.ajax({
			type:'post',
			url:_m_url+'bjTopic/getzhanghaobymanid',
			data:{'mb':mb},
			success:function(data){
	         if(data.length==1){
	        	$("#ind_addWinTable input[qucln=BANK_ID]").val(data[0].ID);
				$("#ind_addWinTable input[qucln=BANK_ID]").attr("chan","T");
				$("#ind_addWinTable input[qucln=BANK_ID]").next().val(data[0].BANK_NO);
				
				$("#ind_addWinTable input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
				$("#ind_addWinTable input[qucln=BANK_NAME]").attr("chan","T");
				$("#ind_addWinTable input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);
				
				$("#ind_addWinTable input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
				$("#ind_addWinTable input[qucln=ACCOUNT_NAME]").attr("chan","T");
				$("#ind_addWinTable input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
	         }else{
	        	 $("#ind_A_ADATAL input[qucln=BANK_ID]").val("");
				 $("#ind_A_ADATAL input[qucln=BANK_ID]").attr("chan","T");
				 $("#ind_A_ADATAL input[qucln=BANK_ID]").next().val("");
				 
				 $("#ind_A_ADATAL input[qucln=BANK_NAME]").val("");
				 $("#ind_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
				 $("#ind_A_ADATAL input[qucln=BANK_NAME]").next().val("");
					
				 $("#ind_A_ADATAL input[qucln=ACCOUNT_NAME]").val("");
				 $("#ind_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
				 $("#ind_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val("");
					
	         }
			}
		});
}



function sethkdui(){
	 var mb=$("#fxhkd_addWinForm input[qucln=MAN_BUSINESS]").val();
		$.ajax({
			type:'post',
			url:_m_url+'bjTopic/getzhanghaobyoid',
			data:{'mb':mb},
			success:function(data){
	         if(data.length==1){
	        	$("#fxhkd_addWinForm input[qucln=BANK_ID]").val(data[0].ID);
				$("#fxhkd_addWinForm input[qucln=BANK_ID]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=BANK_ID]").next().val(data[0].BANK_NO);
				
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);
				
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
				
	         }else{
	        	 $("#fxhkd_addWinForm input[qucln=BANK_ID]").val("");
				 $("#fxhkd_addWinForm input[qucln=BANK_ID]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=BANK_ID]").next().val("");
				 
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").val("");
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").next().val("");
					
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").val("");
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").next().val("");
					
	         }
	         
	         
	         
	         
			}
		});
	
}



//预付单，获得当前营销预算余额并显示
function getYFMarketAmount(){
    var xt_id = $("#bjfkd_A_AFORM input[qucln=XT_ID]").val();
    $.ajax({
        type:'post',
        url:_m_url+'bjTopic/getMarketAmount',
        data:{'xt_id':xt_id},
        success:function(data){
            $("#bjfkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").val(data);
            $("#bjfkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").attr("chan","T");
            $("#bjfkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").next().val(data);
        }
    })
}

//借款单，获得当前营销预算余额并显示
function getJKMarketAmount(){
    var xt_id = $("#bjjkd_A_AFORM input[qucln=XT_ID]").val();
    $.ajax({
        type:'post',
        url:_m_url+'bjTopic/getMarketAmount',
        data:{'xt_id':xt_id},
        success:function(data){
            $("#bjjkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").val(data);
            $("#bjjkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").attr("chan","T");
            $("#bjjkd_A_AFORM input[qucln=MARKET_BUDGET_BALANCE]").next().val(data);
        }
    })
}


function setjkdui(){
	 var mb=$("#bjjkd_A_ADATAL input[qucln=MAN_BUSINESS]").val();
	 var xx=$("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").val();
		$.ajax({
			type:'post',
			url:_m_url+'bjTopic/getzhanghaobyoid',
			data:{'mb':mb},
			success:function(data){
	         if(data.length==1){
	        	$("#bjjkd_A_ADATAL input[qucln=BANK_ID]").val(data[0].ID);
				$("#bjjkd_A_ADATAL input[qucln=BANK_ID]").attr("chan","T");
				$("#bjjkd_A_ADATAL input[qucln=BANK_ID]").next().val(data[0].BANK_NO);
				
				$("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
				$("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
				$("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);
				
				$("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
				$("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
				$("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
				
	         }else{
	        	 $("#bjjkd_A_ADATAL input[qucln=BANK_ID]").val("");
				 $("#bjjkd_A_ADATAL input[qucln=BANK_ID]").attr("chan","T");
				 $("#bjjkd_A_ADATAL input[qucln=BANK_ID]").next().val("");
				 
				 $("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").val("");
				 $("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
				 $("#bjjkd_A_ADATAL input[qucln=BANK_NAME]").next().val("");
					
				 $("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").val("");
				 $("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
				 $("#bjjkd_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val("");
					
	         }
			}
		});
}
/*
 *报销管理：报销费用中根据付款对象拉取对象的银行账号
 */
function getManAccount(){
	//获取付款对象
	var man=$("#bxfy_addWinForm input[qucln=MAN_YUANGONG]").val();
	$.ajax({
		type:'post',
		url:_m_url+'bjTopic/getManAccounts',
		data:{'man':man},
		success:function(data){
         if(data.length==1){
             $("#bxfy_addWinForm input[qucln=ACCOUNT_YG]").val(data[0].ID);
             $("#bxfy_addWinForm input[qucln=ACCOUNT_YG]").attr("chan","T");
             $("#bxfy_addWinForm input[qucln=ACCOUNT_YG]").next().val(data[0].BANK_NO);

             $("#bxfy_addWinForm input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
             $("#bxfy_addWinForm input[qucln=BANK_NAME]").attr("chan","T");
             $("#bxfy_addWinForm input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);

             $("#bxfy_addWinForm input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
             $("#bxfy_addWinForm input[qucln=ACCOUNT_NAME]").attr("chan","T");
             $("#bxfy_addWinForm input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
			
         }else{
        	 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_YG]").val("");
			 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_YG]").attr("chan","T");
			 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_YG]").next().val("");

			 $("#bxfy_A_ADATAL input[qucln=BANK_NAME]").val("");
			 $("#bxfy_A_ADATAL input[qucln=BANK_NAME]").attr("chan","T");
			 $("#bxfy_A_ADATAL input[qucln=BANK_NAME]").next().val("");

			 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_NAME]").val("");
			 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_NAME]").attr("chan","T");
			 $("#bxfy_A_ADATAL input[qucln=ACCOUNT_NAME]").next().val("");
         }
		}
	});
}

function getHkjeMoney(){
	//获取业务对象
	var mb=$('#fxhkd_addWinForm').find('input[qucln=MAN_BUSINESS]').val();
	$.ajax({
		type:'post',
		url:_m_url+'bjTopic/getAllMoney',
		data:{'mb':mb},
		success:function(data){
			$('#fxhkd_addWinForm').find('input[qucln=HKJE_MONEY]').val(data[0].HKJE_MONEY);
			$('#fxhkd_addWinForm').find('input[qucln=HKJE_MONEY]').attr("chan","T");
			$('#fxhkd_addWinForm').find('input[qucln=HKJE_MONEY]').next().val(data[0].HKJE_MONEY);
		}
	});
	var mb=$('#fxhkd_addWinForm').find('input[qucln=MAN_BUSINESS]').val();
		$.ajax({
			type:'post',
			url:_m_url+'bjTopic/getzhanghaobyoid',
			data:{'mb':mb},
			success:function(data){
	         if(data.length==1){
	        	$("#fxhkd_addWinForm input[qucln=BANK_ID]").val(data[0].ID);
				$("#fxhkd_addWinForm input[qucln=BANK_ID]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=BANK_ID]").next().val(data[0].BANK_NO);
				
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").val(data[0].BANK_NAME);
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=BANK_NAME]").next().val(data[0].BANK_NAME);
				
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").val(data[0].ACCOUNT_NAME);
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").attr("chan","T");
				$("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").next().val(data[0].ACCOUNT_NAME);
	         }else{
	        	 $("#fxhkd_addWinForm input[qucln=BANK_ID]").val("");
				 $("#fxhkd_addWinForm input[qucln=BANK_ID]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=BANK_ID]").next().val("");
				 
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").val("");
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=BANK_NAME]").next().val("");
					
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").val("");
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").attr("chan","T");
				 $("#fxhkd_addWinForm input[qucln=ACCOUNT_NAME]").next().val("");
	         }
			}
		});
}

function _data_yf(prefix,dsId,butnId,type,ainitFunc,dataList,dgUrl,queryParams){
	var width = document.documentElement.clientWidth*0.97;
	var height = window.parent.innerHeight-270;
	if($('#'+prefix+'_DATA_WIN').length>0){
		$('#'+prefix+'_DATA_PARENT_PANEL').window('close');
		var obj = document.getElementById(prefix+"_DATA_WIN");
		$('#'+prefix+'_DATA_PARENT_PANEL').remove();
		document.body.removeChild(obj);
	}
	var div_box = document.createElement("DIV");
	div_box.id = prefix+"_DATA_WIN";
	div_box.height = 100;
	document.body.appendChild(div_box);
	$('#'+prefix+'_DATA_WIN').load(_m_url+'singlePages/genFun',
			{'dsId':dsId,'butnId':butnId,'type':type,'staticWebUrl':'','initFunc':'','jspWebUrl':'/model/general/datalistD'},
			function(){
				$.parser.parse('#'+prefix+'_DATA_DG_PANEL');
				$('#'+prefix+'_DATA_PARENT_PANEL').window({  
					width:document.documentElement.clientWidth,  
					     height:document.documentElement.clientHeight,  
					draggable:false,
					top:'0',
					left:'0',
					modal:true,
					resizable:false,
					closable:false,
					collapsible:false,
					maximizable:false,
					minimizable:false
				});  
				$('#'+prefix+'_DATA_PARENT_PANEL').window('open');
				// 加载字段 变不可写 填充数据
				var divName = 'DATA_DATALIST';
				// 加载字段
				$.ajax({
					type:'post',
					url:_m_url+'framework/loadColumnsU',
					data:{'colId':dsId,'type':type},
					success:function(data){
						if(data==""){
							$.messager.alert('提示',"您长时间未操作，系统已经自动退出!，请重新登陆");
						}else{
							var options = jointDGColumn(data[0]);
							var fzClns = options.frozenColumns;
							options.frozenColumns = [[{field:'kk',checkbox:true}]];
							for(var i = 0; i < fzClns[0].length; i ++){
								options.frozenColumns[0].push(fzClns[0][i]);
							}
							//获取div的宽度和高度
							$('#'+prefix+'_DATA_DATALIST').datagrid({
								iconCls:'icon-save',
								pageNumber:1,
								url:dgUrl,
								queryParams:queryParams,
								height:height,
								width:width,
								striped: true,		
								collapsible:true,
								autoRowHeight: false,		
								sortOrder: 'desc',
								remoteSort: false,
								pageList:[300,500,1000],
								columns:options.columns,
								frozenColumns:options.frozenColumns,
								pagination:true,
								rownumbers:true,
								singleSelect:false,
								rowStyler:function(index,row){  
									return window.parent.getRowStyler(index,row,data[0]);
								},
								onRowContextMenu:function(e, rowIndex, rowData){// 右键菜单
								    $('#mm').menu('show', {
								        left:e.pageX,
								        top:e.pageY
								    });
								},
//								onClickRow:function(rowIndex,rowData){
//									//获取到currentIndex
//									var currentIndex=$(this).attr("currentIndex");
//									if(rowIndex!=currentIndex){
//										var colnName=$(this).attr("colnName");
//										$(this).datagrid("endEdit",currentIndex)
//										$(this).datagrid("beginEdit",rowIndex);
//										$(this).attr("currentIndex",rowIndex);
//										var cRowStyle=$($($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").parents("tr[datagrid-row-index]")[0]).attr("class");
//										var amountObj=$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("#editablebox");
//										//清空数量的值
//										$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("input").val("");
//										amountObj.focus();
//										$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("#editablebox").css("background-color","#C9ECFE");
//									}
//								},
								onLoadSuccess:function(data){
									var selRows = $('#bdd_DATA_DATALIST').datagrid('getRows');
									var oldRows = $('#fxhkd_addItemDatagrid').datagrid('getRows');
									if (oldRows.length>0){
										for (var i = 0;i<oldRows.length;i++){
											for (var j=0;j<selRows.length;j++){
												if(oldRows[i].FJ_ID==selRows[j].FJ_ID){
													$('#bdd_DATA_DATALIST').datagrid('deleteRow',j);
												}
											}
									}
									}
									$('#bdd_commDataLeftD').find('select[qucln=IS_FK]').attr('disabled','disabled');
									$('#bdd_commDataLeftD').find('input[qucln=MAN_BUSINESS]').next().attr('disabled',"true");
								}
							});
							$('#'+prefix+'_DATA_DATALIST').datagrid("keyCtr_cp");       // 绑定datagrid 的键盘事件
							if(ainitFunc!='')eval(ainitFunc).call(this,prefix);
						}
					}
				});
			}
		);
}

function getJK(){
	//获取付款对象
	var MAN_YUANGONG=$('#fxhkd_addWinForm').find('input[qucln=MAN_BUSINESS]').val();
	if(MAN_YUANGONG == null || MAN_YUANGONG == ''){
		$.messager.alert('提示','请选择付款对象！');
		return;
	}
	var dgUrl=_m_url+'fxa/findHKD';
	var queryParams={'dsId':'ds_px_hkdselect','MAN_BUSINESS':MAN_YUANGONG};
	$.ajax({
		type:'post',
		url:_m_url+'fxa/findHKD',
		data:{'dsId':'ds_px_hkdselect','MAN_BUSINESS':MAN_YUANGONG},
		success:function(data){
			$.ajax({
				type:'post',
				url:_m_url+'fxa/UpdateDefault',
				data:{'dsId':'ds_px_hkdselect','MAN_BUSINESS':MAN_YUANGONG},
				success:function(data){
				} 
			});
			//根据现成的数据展现窗口
			_data_yf('bdd','ds_px_hkdselect','bdd_sure1','77','DataEndHKD',data,dgUrl,queryParams);		//到款44
		} 
	});
}
function DataEndHKD(prefix){
	//var MAN_BUSINESS=$('#fxhkd_addWinForm').find('input[qucln=MAN_BUSINESS]').val();
	//获取弹框中付款对象
	//$('#bdd_commUseD').find('input[qucln=MAN_BUSINESS]').val(MAN_BUSINESS);
} 
function _bdd_sure1(){
	//关闭弹窗
	$('#bdd_DATA_PARENT_PANEL').window('close');
	//原有明细数据
	var oldRows = $('#fxhkd_addItemDatagrid').datagrid('getRows');
	//获取选择的数据
	var selRows = $('#bdd_DATA_DATALIST').datagrid('getSelections');
	//关闭弹出窗口的editor 
	for(var i=0;i<selRows.length;i++){
		var index=$('#bdd_DATA_DATALIST').datagrid("getRowIndex",selRows[i]);
		$('#bdd_DATA_DATALIST').datagrid('endEdit',index);
	}
	for ( var j = 0; j < selRows.length; j++) {
		$('#fxhkd_addItemDatagrid').datagrid('appendRow', {
			FK_DJCODE:selRows[j].DJ_CODE,
			REAL_MONEY:selRows[j].REAL_MONEY,
			MAN_BUSINESS:selRows[j].MAN_BUSINESS,
			XT_ID:selRows[j].XT_ID,
			MEMO:selRows[j].SHIXIANG,	
			LAST_PAY_DATE:selRows[j].LAST_PAY_DATE,
			XT_PUB_ID:selRows[j].PUB_ID,
			INPUT_MAN:selRows[j].INPUT_MAN,
			INPUT_DATE:selRows[j].INPUT_DATE,
			TRANSLATOR:selRows[j].TRANSLATOR,
			XT_AUTHOR:selRows[j].AUTHOR,
			XT_ISBN:selRows[j].H_ISBN,
			FJ_ID:selRows[j].FJ_ID,
			YJ_MONEY_LOCK:selRows[j].YJ_MONEY_LOCK,
			YJ_REST_MONEY:selRows[j].YJ_REST_MONEY,
			YJ_USE_MONEY:selRows[j].YJ_USE_MONEY,
			USE_MONEY_TX:0
		});
	}
}
function deleteHk(obj,dgUrl,queryParams){
	//获取选中的行
	var oldRows = $('#fxhkd_addItemDatagrid').datagrid('getSelections');
	var MAN_BUSINESS=$('#fxhkd_addWinForm').find('input[qucln=MAN_BUSINESS]').val();
	var hk_id=$('#fxhkd_addWinForm').find('input[qucln=HK_ID]').val();
	for(var i=0;i<oldRows.length;i++){
		var rowIndex= $('#fxhkd_addItemDatagrid').datagrid('getRowIndex',oldRows[i]);
		$('#fxhkd_addItemDatagrid').datagrid('deleteRow',rowIndex);
	}
	for ( var j = 0; j < oldRows.length; j++) {
		//把选择的付款单从关联表中删除
		$.ajax({
			type:'post',
			url:_m_url+'fxa/deleteHK',
			data:{'HK_ID':hk_id,'MAN_BUSINESS':MAN_BUSINESS,'fj_id':oldRows[j].FJ_ID},
			success:function(data){
				console.log('删除还款单成功！');
			} 
		});
		$('#bdd_DATA_DATALIST').datagrid('appendRow', {
			FK_DJCODE:oldRows[j].DJ_CODE,
			REAL_MONEY:oldRows[j].REAL_MONEY,
			MAN_BUSINESS:oldRows[j].MAN_BUSINESS,
			XT_ID:oldRows[j].XT_ID,
			MEMO:oldRows[j].SHIXIANG,	
			LAST_PAY_DATE:oldRows[j].LAST_PAY_DATE,
			XT_PUB_ID:oldRows[j].PUB_ID,
			INPUT_MAN:oldRows[j].INPUT_MAN,
			INPUT_DATE:oldRows[j].INPUT_DATE,
			TRANSLATOR:oldRows[j].TRANSLATOR,
			XT_AUTHOR:oldRows[j].AUTHOR,
			XT_ISBN:oldRows[j].H_ISBN,
			FJ_ID:oldRows[j].FJ_ID,
			YJ_MONEY_LOCK:oldRows[j].YJ_MONEY_LOCK,
			YJ_REST_MONEY:oldRows[j].YJ_REST_MONEY,
			YJ_USE_MONEY:oldRows[j].YJ_USE_MONEY
		});
	}
}

/***
 * 财务：报销单和综合费用单的批量审核
 * @param obj
 * @return
 */
function all_CwPlButn(obj){
	var flag = $(obj).attr('flag');// 判断是单据类型
	var buParams = {};
	buParams.dsid = $(obj).attr('dsid');
	buParams.code = $(obj).attr('code');	
	buParams.prefix=$(obj).attr('pre');	
	var djId='';
	var selRows = $('#'+$(obj).attr('pre')+'_DATALIST').datagrid('getSelections');  //获取勾选的数据
	
	if(!(selRows.length > 0)){
		$.messager.alert("提示信息","请选中一行或多行","info");
		return;
	}else if(selRows.length>300){
		$.messager.alert("提示信息","选择的审核数据不准大于300行","info");
		return;
	}else{
		$.messager.confirm('提示','确定批量审核操作?', function(ispl){
			// 点击确定则保存,否则取消
		    if (ispl) {
		    	// 获取主键
		    	var pk = eval("window.parent."+$(obj).attr('dsid').split(";")[0]+"_pk");
		    	// 测试循环
				for(var i = 0; i < selRows.length; i++){
					djId += selRows[i][pk];
					if(i < selRows.length-1){
						djId +=';';
					}
				}
				buParams.djId = djId;
				$.ajax({
					url:_m_url+'butpro/cwPlVerifyButn',
					type:'post',
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					async:false,
					data:JSON.stringify(buParams),
					success:function(data){
						if(data.msg == 'success'){
							$.messager.alert("提示信息",data.info);
						}else if(data.msg == 'fail'){
							$.messager.alert("提示信息",data.info);
						}else{
							$.messager.alert("错误信息",data.info);
						}
					}
				});
		    }
		});
	}
}
/***
 * 财务：预付单和借款的批量付款
 * @param obj
 * @return
 */
function all_CwPlFKButn(obj){
	var flag = $(obj).attr('flag');// 判断是单据类型
	var buParams = {};
	buParams.dsid = $(obj).attr('dsid');
	buParams.code = $(obj).attr('code');	
	buParams.prefix=$(obj).attr('pre');	
	var djId='';
	var selRows = $('#'+$(obj).attr('pre')+'_DATALIST').datagrid('getSelections');  //获取勾选的数据
	
	if(!(selRows.length > 0)){
		$.messager.alert("提示信息","请选中一行或多行","info");
		return;
	}else if(selRows.length>300){
		$.messager.alert("提示信息","选择的付款数据不准大于300行","info");
		return;
	}else{
		$.messager.confirm('提示','确定批量付款操作?', function(ispl){
			// 点击确定则保存,否则取消
		    if (ispl) {
		    	// 获取主键
		    	var pk = eval("window.parent."+$(obj).attr('dsid').split(";")[0]+"_pk");
		    	// 测试循环
				for(var i = 0; i < selRows.length; i++){
					djId += selRows[i][pk];
					if(i < selRows.length-1){
						djId +=';';
					}
				}
				buParams.djId = djId;
				$.ajax({
					url:_m_url+'butpro/cwPlFUKUANButn',
					type:'post',
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					async:false,
					data:JSON.stringify(buParams),
					success:function(data){
						if(data.msg == 'success'){
							$.messager.alert("提示信息",data.info);
						}else if(data.msg == 'fail'){
							$.messager.alert("提示信息",data.info);
						}else{
							$.messager.alert("错误信息",data.info);
						}
					}
				});
		    }
		});
	}
}


/**
 * 综合费用（添加按钮明细）
 *
 * @param obj
 * @return
 */
function INDAdd(obj) {
    var allrow = $('#ind_addItemDatagrid').datagrid('getRows');
    for ( var i = 0; i < allrow.length; i++) {
        $('#ind_addItemDatagrid').datagrid('endEdit', i);
    }
    var orderNum = 0;
    if (allrow.length > 0) {
        orderNum = allrow[allrow.length - 1].SORT_NUMBER;
    } else {
        orderNum = 0;
    }
    if (orderNum == '' || orderNum == null) {
        orderNum = 10;
    } else {
        orderNum = parseInt(orderNum) + 10;
    }
    var lastIndex;
    var row = {
        'SORT_NUMBER' : orderNum
    };
    $('#ind_addItemDatagrid').datagrid('appendRow', row);
    $('#ind_addItemDatagrid').datagrid( {
        onClickRow : function(rowIndex, rowData) {
            $('#ind_addItemDatagrid').attr("currentIndex", rowIndex);
            $('#ind_addItemDatagrid').datagrid('endEdit', lastIndex);
            $('#ind_addItemDatagrid').datagrid('beginEdit', rowIndex);
            lastIndex = rowIndex;
        }
    });
}

// 删除 （综合费用）
function INDDel(obj) {
    var row = $('#ind_addItemDatagrid').datagrid('getSelected');
    if (row == null) {
        $.messager.alert("操作提示", "请选择一条记录,在进行 删除！", "info");
        return;
    } else {
        var rowIndex = $('#ind_addItemDatagrid').datagrid('getRowIndex', row);
        if(row.FIN_TYPE =='13B3EC66C5222FE4B0923A1937B4DDEB'){
            $.messager.alert('提示','您已删除营销费用，请点【使用营销预算余额】中的清除金额！');
        }
        $('#ind_addItemDatagrid').datagrid('deleteRow', rowIndex);
    }
}

/**
 * 报销费用（添加按钮明细）
 *
 * @param obj
 * @return
 */
function BXFYAdd(obj) {
    var allrow = $('#bxfy_addItemDatagrid').datagrid('getRows');
    for ( var i = 0; i < allrow.length; i++) {
        $('#bxfy_addItemDatagrid').datagrid('endEdit', i);
    }
    var orderNum = 0;
    if (allrow.length > 0) {
        orderNum = allrow[allrow.length - 1].SORT_NUMBER;
    } else {
        orderNum = 0;
    }
    if (orderNum == '' || orderNum == null) {
        orderNum = 10;
    } else {
        orderNum = parseInt(orderNum) + 10;
    }
    var lastIndex;
    var row = {
        'SORT_NUMBER' : orderNum
    };
    var isF = true;
    $('#bxfy_addItemDatagrid').datagrid('appendRow', row);
    $('#bxfy_addItemDatagrid').datagrid( {
        onClickRow : function(rowIndex, rowData) {
            $('#bxfy_addItemDatagrid').attr("currentIndex", rowIndex);
            $('#bxfy_addItemDatagrid').datagrid('endEdit', lastIndex);
            $('#bxfy_addItemDatagrid').datagrid('beginEdit', rowIndex);
            lastIndex = rowIndex;
        }
    });
}

// 删除 （报销费用）
function BXFYDel(obj) {
    var row = $('#bxfy_addItemDatagrid').datagrid('getSelected');
    if (row == null) {
        $.messager.alert("操作提示", "请选择一条记录,在进行 删除！", "info");
        return;
    } else {
        var rowIndex = $('#bxfy_addItemDatagrid').datagrid('getRowIndex', row);
        if(row.FIN_TYPE =='13B3EC66C5222FE4B0923A1937B4DDEB'){
            $.messager.alert('提示','您已删除营销费用，请点【使用营销预算余额】中的清除金额！');
        }
        $('#bxfy_addItemDatagrid').datagrid('deleteRow', rowIndex);
    }
}

//以下是报销费用的【使用营销额度】按钮
//使用营销额度按钮的执行方法
function useYXED(obj,dgUrl,queryParams){
    var djcode = $('#bxfy_addWinForm').find('input[qucln=DJ_CODE]').val();	//判断该单据是否已经点击使用保存
    if(djcode == null || djcode == ''){
        $.messager.alert('提示','请您先保存本单据！');
        return;
    }
    //red    bxfy
    //redhx  bxfyed
    //common_save(obj);
    var dsId = $(obj).attr('dsId');
    var clientId = $('#bxfy_addWinForm').find('input[qucln=XT_ID]').val(); 	//客户id
    var chid = $('#bxfy_addWinForm').find('input[qucln=BXFY_ID]').val();	//主表主键
    if(clientId == null || clientId == ''){
        $.messager.alert('提示','请选择选题名称！');
        return;
    }
//加载中间表的数据
    $.ajax({
        type:'post',
        url:_m_url+'fxa/findBXFYEDYs',
        data:{'dsId':'ds_bx_expensesClaim_item2',"clientId":clientId},
        success:function(tempData){
            for ( var i = 0; i < tempData.length; i++) {
                var chidcache =  tempData[i].BXFY_ID;
            }
            var dgUrl=_m_url+'fxa/findBXFYEDYs';
            var queryParams={'dsId':'ds_bx_expensesClaim_item2','clientId':clientId,'chid':chid,'chidcache':chidcache};
            $.ajax({
                type:'post',
                url:_m_url+'fxa/queryBXFYYS',
                data:{'dsId':'ds_bx_expensesClaim_item2','clientId':clientId,'chid':chid,'chidcache':chidcache},
                success:function(data){
                    //根据现成的数据展现窗口
                    _data_qw('bxfyed','ds_bx_expensesClaim_item2','bxfyed_sure1','77','bxfythenData',data,dgUrl,queryParams);	//预收 44
                }
            });
        }
    })
}
//加载数据完成之后的回调函数
function bxfythenData(prefix){
    //去掉charbox列
    //1,获取需要操作的datagrid
    $('#'+prefix+'_DATA_TAB_PANEL').find('td[field=kk]').remove();
    //获取主键Id
    var skId = $('#bxfy_addWinForm').find('input[qucln=BXFY_ID]').val();
    //使用预收
    var ysje = $('#bxfyed_addWinForm').find('input[qucln=USE_MONEY_TX]').val();
    if(ysje == null || ysje == ''){
        ysje =0;
    }

    ////给弹出窗口中的按钮后加剩余金额
    var syje = 	appFunc(0);

    if(syje < 0){
        $('#bxfyed_commDataLeftD').append("可冲减预付金额为："+syje+",金额为负数，建议调整主表金额！");
    }else{
        $('#bxfyed_commDataLeftD').append("本单营销费用总金额为："+syje);//+",本单使用预付总金额为："+ysje
    }
    var allData = new Array();
    //加载当前结算单   在关联表中使用的金额赋值
    if(skId !=null && skId !=''){
        $.ajax({
            type:'post',
            url:_m_url+'fxa/findDzysData',
            data:{'skId':skId},
            async:false,
            success:function(data){
                allData = data;
            }
        })
    }
    var allRows = $('#bxfyed_DATA_DATALIST').datagrid('getRows');
    for(var i = 0;i<allRows.length;i++){
        var ysId = allRows[i].YS_ID;  			//预收Id
        var zje = allRows[i].YS_MONEY;  		//预收金额
        var zyMoney = allRows[i].YW_CODE.YS_MONEY_LOCK; //预收锁定金额
        var syMoney = allRows[i].YS_MONEY_USED; //已经使用的预收金额
        if(zje == null || zje == ''){
            zje =0;
        }
        if(zyMoney == null || zyMoney == ''){
            zyMoney = 0;
        }
        if(syMoney == null || syMoney == ''){
            syMoney = 0;
        }
        //总的预收金额-锁定金额-已使用预收金额  如果小于0 则不出现在列表数据中
        if(zje-zyMoney-syMoney<0){
            $('#bxfyed_DATA_DATALIST').datagrid('deleteRow',i);
        }
        //如果查询数据返回length>0
        if(allData.length>0){
            for(var j=0;j<allData.length;j++){
                //循环  如果当前数据的ysId = 返回数据的ysId  则将返回数据的使用金额 填充到当前行
                if(ysId == allData[j].YS_ID){
                    allRows[i].USE_MONEY_TX = allData[j].YS_MONEY_OCCUPY;		//使用金额赋值占用金额  YS_MONEY_OCCUPY
                    allRows[i].YS_MONEY_LOCK = (allRows[i].YS_MONEY_LOCK - allData[j].YS_MONEY_OCCUPY);
                    allRows[i].YS_MONEY_KY =  (allRows[i].YS_MONEY_KY + allData[j].YS_MONEY_OCCUPY);

                    $('#bxfyed_DATA_DATALIST').datagrid('beginEdit',i);
                    $('#bxfyed_DATA_DATALIST').datagrid('endEdit',i);
                    $('#bxfyed_DATA_DATALIST').datagrid('selectRow',i);  //如果有使用金额则选中该行
                }
            }
        }
    }
}

//使用营销额度按钮中的确定按钮
function _bxfyed_sure(){
    //获取收款ID
    var chid = $('#bxfy_addWinTable input[qucln=BXFY_ID]').val();

    //获取弹窗中的全部数据
    var selRows = $('#bxfyed_DATA_DATALIST').datagrid('getRows');
    //预收金额
    var ysje = $('#bxfyed_addWinForm').find('input[qucln=YS_MONEY]').val();
    ysje = parseFloat(ysje).toFixed(2);
    //已使用金额
    var ysyje = $('#bxfyed_addWinForm').find('input[qucln=YS_MONEY_USED]').val();
    ysyje = parseFloat(ysyje).toFixed(2);
    //占用金额
    var zyje = $('#bxfyed_addWinForm').find('input[qucln=YS_MONEY_LOCK]').val();
    zyje = parseFloat(zyje).toFixed(2);
    //预付余额=预收金额-已使用金额-占用金额
    var yfye = parseFloat(ysje - ysyje - zyje).toFixed(2);
    //关闭弹出窗口的editor
    for(var i=0;i<selRows.length;i++){
        var index=$('#bxfyed_DATA_DATALIST').datagrid("getRowIndex",selRows[i]);
        $('#bxfyed_DATA_DATALIST').datagrid('endEdit',index);
    }
    var allMoney = 0;
    var str = "";
    for(var i = 0;i<selRows.length;i++){
        if(selRows[i].USE_MONEY_TX > selRows[i].PREPAID_BALANCE){
            $.messager.alert('提示','选中行中存在使用预付大于可用预付的数据！请检查');
            return;
        }else{
            if(selRows[i].USE_MONEY_TX == null || selRows[i].USE_MONEY_TX == ''){
                selRows[i].USE_MONEY_TX = 0;
            }
            if(selRows[i].USE_MONEY_TX != 0){
                allMoney = parseFloat(allMoney)+ parseFloat(selRows[i].USE_MONEY_TX);
                //将使用预收的预收Id和预收金额进行拼接放到前面界面上
                //拼接方式：ysId1|ysMoney1;ysId2|ysMoney2;......
                str += selRows[i].YS_CODE+'|'+parseFloat(selRows[i].USE_MONEY_TX);
                if(i<selRows.length-1){
                    str +=';';
                }
            }
        }
    }
    allMoney = allMoney.toFixed(2);
    if(parseFloat(allMoney) > parseFloat(yfye)){
        $.messager.alert('温馨提示','亲，本单使用金额'+allMoney+'不可大于(应收款-使用到款)'+yfye+'！请修改本单使用金额');
        return;
    }else{
        //关闭弹窗
        $('#bxfyed_DATA_PARENT_PANEL').window('close');
        //把str 放入界面上
        $('#bxfy_t_ysId').val(str);
        //点击确定的时候向中间表插入数据
        saveDZYS();
        //给使用预收列赋值
        $('#bxfy_addWinForm').find('input[qucln=USE_MONEY]').val(allMoney);
        $('#bxfy_addWinForm').find('input[qucln=USE_MONEY]').attr('chan','T');
        $('#bxfy_addWinForm').find('input[qucln=USE_MONEY]').next().val(allMoney);
        ////调用计算方法
        //jsgsFunc();
    }
}

//报销费用中的自动金额按钮
function _bxfyed_zdjeFunc(){
    var syje = 	appFunc(0);
    var allRows = $('#bxfyed_DATA_DATALIST').datagrid('getRows');
    //获取主键Id
    var bxId = $('#bxfy_addWinForm').find('input[qucln=BXFY_ID]').val();
    if(allRows.length == 0){
        $.messager.alert('温馨提示','亲，没有预付数据可使用！');
        return;
    }else{
        if(syje <= 0){
            $.messager.alert('温馨提示','亲，当前单据可用金额为零，不需使用预付金额！');
            return;
        }else{
            var syData = new Array();
            if(  bxId !=null && bxId !=''){
                $.ajax({
                    type:'post',
                    url:_m_url+'fxa/findbxData',
                    data:{'bxId':bxId},
                    async:false,
                    success:function(data){
                        syData = data;
                    }
                })}
            //如果查询数据返回length>0
            var sum=0;
            for(var j =0;j<syData.length;j++){
                var zzy=syData[j].BX_MONEY_OCCUPY;
                if(zzy == null || zzy == ''){
                    zzy = 0;
                }
                sum +=zzy;
            }
                for(var i =0;i<allRows.length;i++){
                    var kyMoney = allRows[i].PREPAID_BALANCE; //预收余额
                    var sy=allRows[i].USE_MONEY_TX;
                    if(kyMoney == null || kyMoney == ''){
                        kyMoney = 0;
                    }
                    if(sy == null || sy == ''){
                        sy = 0;
                    }
                    if(syje > 0){
                        if (sum<=sy){
                            if(syje > kyMoney){
                                allRows[i].USE_MONEY_TX = allRows[i].PREPAID_BALANCE;
                            }else{
                                allRows[i].USE_MONEY_TX = syje;
                            }
                            $('#bxfyed_DATA_DATALIST').datagrid('beginEdit',i);
                            $('#bxfyed_DATA_DATALIST').datagrid('endEdit',i);
                            syje = syje - kyMoney;
                        }else{
                            $.messager.alert('温馨提示','亲，已经使用了自动金额，不能重复使用自动金额！');
                            return;
                        }
                    }
                }



        }
    }
}
//使用营销额度中的清除金额按钮方法
function _bxfyed_remove(){
    var chid = $("#bxfy_addWinTable").find("input[qucln='BXFY_ID']").val();
    var rows = $("#bxfyed_DATA_DATALIST").datagrid("getRows");
    for ( var i = 0; i < rows.length; i++) {
        rows[i].USE_MONEY_TX = "";
        $("#bxfyed_DATA_DATALIST").datagrid("beginEdit",i);
        $("#bxfyed_DATA_DATALIST").datagrid("endEdit",i);
    }
    $.ajax({
        type:"post",
        url:_m_url+'fxa/bxfyedremovemoney',
        data:{'chid':chid},
        success:function(data){
        }
    })
}
//获取本单审稿费总金额
function appFunc(flag){
    //预付余额
    var syje = 0;
    var bdje = 0;
    var sum=0;
    var allRows = $('#bxfy_addItemDatagrid').datagrid('getRows');
    for(var i = 0; i <allRows.length ; i++){
        var djTp = allRows[i].FIN_TYPE ;
        if(djTp =='13B3EC66C5222FE4B0923A1937B4DDEB'){
            zsk = parseFloat(allRows[i]["REAL_MONEY"]);
            sum +=zsk;
        }else{
            syje=0;
        }

    }

    if(flag == 0){ //使用预收
        syje = (parseFloat(sum)).toFixed(2);
    }
    return syje;
}
//预算的保存
function saveDZYS(){
    //获取本单的主键和预收单的数据
    var skpk = $('#bxfy_addWinTable input[qucln = BXFY_ID]').val();
    //var YSID = $('#redhx_DATA_DATALIST').find('input[qucln=YS_CODE]').val();
    var allRows = $('#bxfyed_DATA_DATALIST').datagrid('getRows');
    for(var i = 0;i<allRows.length;i++){
        var ysId = allRows[i].YS_CODE;  			//预收Id
    }
    var YSID=ysId;
    var XT_ID = $('#bxfy_addWinTable input[qucln = XT_ID]').val();
    var ysStr = $('#bxfy_t_ysId').val();
    var skOptions = new Array();
    var ysAllOption= new Array();
    var ysList = new Array();
    ysList = ysStr.split(";");
    for(var i=0;i<ysList.length;i++){
        var option = {};
        var ysOption = new Array();
        ysOption = ysList[i].split('|');
        option.ysId = ysOption[0];
        option.useMoney = ysOption[1];
        ysAllOption.push(option);
    }
    skOptions.push(ysAllOption);
    $.ajax({
        type:'post',
        url:_m_url+'fxa/saveBxfyYS?skId='+skpk+'&YSID='+YSID+'&XT_ID='+XT_ID,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        data:JSON.stringify(skOptions),
        success:function(data){
        }
    })
}


//以下都是综合费用【使用营销额度】的方法

//使用营销额度按钮的执行方法
function useZHYXED(obj,dgUrl,queryParams){
    //bxfy    ind
    //bxfyed  indhs
    var djcode = $('#ind_addWinForm').find('input[qucln=DJ_CODE]').val();	//判断该单据是否已经点击使用保存
    if(djcode == null || djcode == ''){
        $.messager.alert('提示','请您先保存本单据！');
        return;
    }
    //common_save(obj);
    var dsId = $(obj).attr('dsId');
    var clientId = $('#ind_addWinForm').find('input[qucln=XT_ID]').val(); 	//客户id
    var chid = $('#ind_addWinForm').find('input[qucln=BXFY_ID]').val();	//主表主键
    if(clientId == null || clientId == ''){
        $.messager.alert('提示','请选择选题名称！');
        return;
    }
//加载中间表的数据
    $.ajax({
        type:'post',
        url:_m_url+'fxa/findBXFYEDYs',
        data:{'dsId':'ds_cw_indicator_item2',"clientId":clientId},
        success:function(tempData){
            for ( var i = 0; i < tempData.length; i++) {
                var chidcache =  tempData[i].BXFY_ID;
            }
            var dgUrl=_m_url+'fxa/findBXFYEDYs';
            var queryParams={'dsId':'ds_cw_indicator_item2','clientId':clientId,'chid':chid,'chidcache':chidcache};
            $.ajax({
                type:'post',
                url:_m_url+'fxa/queryBXFYYS',
                data:{'dsId':'ds_cw_indicator_item2','clientId':clientId,'chid':chid,'chidcache':chidcache},
                success:function(data){
                    //根据现成的数据展现窗口
                    _data_qw('indhs','ds_cw_indicator_item2','indhs_sure1','77','thenData',data,dgUrl,queryParams);	//预收 44
                }
            });
        }
    })
}
//加载数据完成之后的回调函数
function thenData(prefix){
    //去掉charbox列
    //1,获取需要操作的datagrid
    $('#'+prefix+'_DATA_TAB_PANEL').find('td[field=kk]').remove();
    //获取主键Id
    var skId = $('#ind_addWinForm').find('input[qucln=BXFY_ID]').val();
    //使用预收
    var ysje = $('#indhs_addWinForm').find('input[qucln=USE_MONEY_TX]').val();
    if(ysje == null || ysje == ''){
        ysje =0;
    }

    ////给弹出窗口中的按钮后加剩余金额
    var syje = 	indappFunc(0);

    if(syje < 0){
        $('#indhs_commDataLeftD').append("可冲减预付金额为："+syje+",金额为负数，建议调整主表金额！");
    }else{
        $('#indhs_commDataLeftD').append("本单营销费用总金额为："+syje);//+",本单使用预付总金额为："+ysje
    }
    var allData = new Array();
    //加载当前结算单   在关联表中使用的金额赋值
    if(skId !=null && skId !=''){
        $.ajax({
            type:'post',
            url:_m_url+'fxa/findDzysData',
            data:{'skId':skId},
            async:false,
            success:function(data){
                allData = data;
            }
        })
    }
    var allRows = $('#indhs_DATA_DATALIST').datagrid('getRows');
    for(var i = 0;i<allRows.length;i++){
        var ysId = allRows[i].YS_ID;  			//预收Id
        var zje = allRows[i].YS_MONEY;  		//预收金额
        var zyMoney = allRows[i].YW_CODE.YS_MONEY_LOCK; //预收锁定金额
        var syMoney = allRows[i].YS_MONEY_USED; //已经使用的预收金额
        if(zje == null || zje == ''){
            zje =0;
        }
        if(zyMoney == null || zyMoney == ''){
            zyMoney = 0;
        }
        if(syMoney == null || syMoney == ''){
            syMoney = 0;
        }
        //总的预收金额-锁定金额-已使用预收金额  如果小于0 则不出现在列表数据中
        if(zje-zyMoney-syMoney<0){
            $('#indhs_DATA_DATALIST').datagrid('deleteRow',i);
        }
        //如果查询数据返回length>0
        if(allData.length>0){
            for(var j=0;j<allData.length;j++){
                //循环  如果当前数据的ysId = 返回数据的ysId  则将返回数据的使用金额 填充到当前行
                if(ysId == allData[j].YS_ID){
                    allRows[i].USE_MONEY_TX = allData[j].YS_MONEY_OCCUPY;		//使用金额赋值占用金额  YS_MONEY_OCCUPY
                    allRows[i].YS_MONEY_LOCK = (allRows[i].YS_MONEY_LOCK - allData[j].YS_MONEY_OCCUPY);
                    allRows[i].YS_MONEY_KY =  (allRows[i].YS_MONEY_KY + allData[j].YS_MONEY_OCCUPY);

                    $('#indhs_DATA_DATALIST').datagrid('beginEdit',i);
                    $('#indhs_DATA_DATALIST').datagrid('endEdit',i);
                    $('#indhs_DATA_DATALIST').datagrid('selectRow',i);  //如果有使用金额则选中该行
                }
            }
        }
    }
}

//使用营销额度按钮中的确定按钮
function _indhs_sure(){
    //获取收款ID
    var chid = $('#ind_addWinTable input[qucln=BXFY_ID]').val();

    //获取弹窗中的全部数据
    var selRows = $('#indhs_DATA_DATALIST').datagrid('getRows');
    //预收金额
    var ysje = $('#indhs_addWinForm').find('input[qucln=YS_MONEY]').val();
    ysje = parseFloat(ysje).toFixed(2);
    //已使用金额
    var ysyje = $('#indhs_addWinForm').find('input[qucln=YS_MONEY_USED]').val();
    ysyje = parseFloat(ysyje).toFixed(2);
    //占用金额
    var zyje = $('#indhs_addWinForm').find('input[qucln=YS_MONEY_LOCK]').val();
    zyje = parseFloat(zyje).toFixed(2);
    //预付余额=预收金额-已使用金额-占用金额
    var yfye = parseFloat(ysje - ysyje - zyje).toFixed(2);
    //关闭弹出窗口的editor
    for(var i=0;i<selRows.length;i++){
        var index=$('#indhs_DATA_DATALIST').datagrid("getRowIndex",selRows[i]);
        $('#indhs_DATA_DATALIST').datagrid('endEdit',index);
    }
    var allMoney = 0;
    var str = "";
    for(var i = 0;i<selRows.length;i++){
        if(selRows[i].USE_MONEY_TX > selRows[i].PREPAID_BALANCE){
            $.messager.alert('提示','选中行中存在使用预付大于可用预付的数据！请检查');
            return;
        }else{
            if(selRows[i].USE_MONEY_TX == null || selRows[i].USE_MONEY_TX == ''){
                selRows[i].USE_MONEY_TX = 0;
            }
            if(selRows[i].USE_MONEY_TX != 0){
                allMoney = parseFloat(allMoney)+ parseFloat(selRows[i].USE_MONEY_TX);
                //将使用预收的预收Id和预收金额进行拼接放到前面界面上
                //拼接方式：ysId1|ysMoney1;ysId2|ysMoney2;......
                str += selRows[i].YS_CODE+'|'+parseFloat(selRows[i].USE_MONEY_TX);
                if(i<selRows.length-1){
                    str +=';';
                }
            }
        }
    }
    allMoney = allMoney.toFixed(2);
    if(parseFloat(allMoney) > parseFloat(yfye)){
        $.messager.alert('温馨提示','亲，本单使用金额'+allMoney+'不可大于(应收款-使用到款)'+yfye+'！请修改本单使用金额');
        return;
    }else{
        //关闭弹窗
        $('#indhs_DATA_PARENT_PANEL').window('close');
        //把str 放入界面上
        $('#ind_t_ysId').val(str);
        //点击确定的时候向中间表插入数据
        indsaveDZYS();
        //给使用预收列赋值
        $('#ind_addWinForm').find('input[qucln=USE_MONEY]').val(allMoney);
        $('#ind_addWinForm').find('input[qucln=USE_MONEY]').attr('chan','T');
        $('#ind_addWinForm').find('input[qucln=USE_MONEY]').next().val(allMoney);
        ////调用计算方法
        //jsgsFunc();
    }
}

//使用营销额度中的自动金额按钮
function _indhs_zdjeFunc(){
    var syje = 	indappFunc(0);
    var allRows = $('#indhs_DATA_DATALIST').datagrid('getRows');
    //获取主键Id
    var bxId = $('#ind_addWinForm').find('input[qucln=EXES_ID]').val();
    if(allRows.length == 0){
        $.messager.alert('温馨提示','亲，没有预付数据可使用！');
        return;
    }else{
        if(syje <= 0){
            $.messager.alert('温馨提示','亲，当前单据可用金额为零，不需使用预付金额！');
            return;
        }else{
            var syData = new Array();
            if(  bxId !=null && bxId !=''){
                $.ajax({
                    type:'post',
                    url:_m_url+'fxa/findbxData',
                    data:{'bxId':bxId},
                    async:false,
                    success:function(data){
                        syData = data;
                    }
                })}
            var sum=0;
            for(var j =0;j<syData.length;j++){
                var zzy=syData[j].BX_MONEY_OCCUPY;
                if(zzy == null || zzy == ''){
                    zzy = 0;
                }
                sum +=zzy;
            }

            for(var i =0;i<allRows.length;i++){
                var kyMoney = allRows[i].PREPAID_BALANCE; //预收余额
                var sy=allRows[i].USE_MONEY_TX;

                if(kyMoney == null || kyMoney == ''){
                    kyMoney = 0;
                }
                if(sy == null || sy == ''){
                    sy = 0;
                }

                if(syje > 0){
                    if (sum<=sy){

                        if(syje > kyMoney){
                        allRows[i].USE_MONEY_TX = allRows[i].PREPAID_BALANCE;
                    }else{
                        allRows[i].USE_MONEY_TX = syje;
                    }
                    $('#indhs_DATA_DATALIST').datagrid('beginEdit',i);
                    $('#indhs_DATA_DATALIST').datagrid('endEdit',i);
                    syje = syje - kyMoney;
                }else{
                        $.messager.alert('温馨提示','亲，已经使用了自动金额，不能重复使用自动金额！');
                        return;
                    }
                }
            }
        }
    }
}
//使用营销额度中的清除金额按钮方法
function _indhs_remove(){
    var chid = $("#ind_addWinTable").find("input[qucln='EXES_ID']").val();
    var rows = $("#indhs_DATA_DATALIST").datagrid("getRows");
    for ( var i = 0; i < rows.length; i++) {
        rows[i].USE_MONEY_TX = "";
        $("#indhs_DATA_DATALIST").datagrid("beginEdit",i);
        $("#indhs_DATA_DATALIST").datagrid("endEdit",i);
    }
    $.ajax({
        type:"post",
        url:_m_url+'fxa/bxfyedremovemoney',
        data:{'chid':chid},
        success:function(data){
        }
    })
}
//获取本单审稿费总金额
function indappFunc(flag){
    //预付余额
    var syje = 0;
    var bdje = 0;
    var sum=0;
    var allRows = $('#ind_addItemDatagrid').datagrid('getRows');
    for(var i = 0; i <allRows.length ; i++){
        var djTp = allRows[i].FIN_TYPE ;
        if(djTp =='13B3EC66C5222FE4B0923A1937B4DDEB'){
            zsk = parseFloat(allRows[i]["REAL_MONEY"]);
            sum +=zsk;
        }else{
            syje=0;
        }

    }

    if(flag == 0){ //使用预收
        syje = (parseFloat(sum)).toFixed(2);
    }
    return syje;
}
//预算的保存
function indsaveDZYS(){
    //获取本单的主键和预收单的数据
    var skpk = $('#ind_addWinTable input[qucln = EXES_ID]').val();
    //var YSID = $('#redhx_DATA_DATALIST').find('input[qucln=YS_CODE]').val();
    var allRows = $('#indhs_DATA_DATALIST').datagrid('getRows');
    for(var i = 0;i<allRows.length;i++){
        var ysId = allRows[i].YS_CODE;  			//预收Id
    }
    var YSID=ysId;
    var XT_ID = $('#ind_addWinTable input[qucln = XT_ID]').val();
    var ysStr = $('#ind_t_ysId').val();
    var skOptions = new Array();
    var ysAllOption= new Array();
    var ysList = new Array();
    ysList = ysStr.split(";");
    for(var i=0;i<ysList.length;i++){
        var option = {};
        var ysOption = new Array();
        ysOption = ysList[i].split('|');
        option.ysId = ysOption[0];
        option.useMoney = ysOption[1];
        ysAllOption.push(option);
    }
    skOptions.push(ysAllOption);
    $.ajax({
        type:'post',
        url:_m_url+'fxa/saveBxfyYS?skId='+skpk+'&YSID='+YSID+'&XT_ID='+XT_ID,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        data:JSON.stringify(skOptions),
        success:function(data){
        }
    })
}

